﻿using Newtonsoft.Json;
using System.ComponentModel;
using System.Windows;
using VisionDesigner.ImageEnhance;
using VM.Common.Enums;
using VM.Common.Helper;

namespace Plugin.Enhance
{
    [JsonObject(MemberSerialization.OptOut)]
    public class ParamModel : NotifyPropertyBase
    {
        [Newtonsoft.Json.JsonIgnore]
        public Dictionary<string, string> ParamMap = new Dictionary<string, string>
        {

            { "锐化", "Sharpen" },
            { "对比度", "Contrast" },
            { "伽马", "Gamma" },
            { "亮度校正", "BrightAdjust" },



        };



        // 图像增强方式方式
        private List<string> _EnhanceTypeArray = EnumHelper.GetEnumDescriptions<EnhanceTypes>();
        [Newtonsoft.Json.JsonIgnore]
        public List<string> EnhanceTypeArray
        {
            get { return _EnhanceTypeArray; }
            set { Set(ref _EnhanceTypeArray, value); }
        }
        //滑动快最大最小
        private int _Zengyi = 0;
        public int Zengyi
        {
            get { return _Zengyi; }
            set
            {
                Set(ref _Zengyi, value);
            }
        }
        private int _Light = 0;
        public int Light
        {
            get { return _Light; }
            set
            {
                Set(ref _Light, value);

            }
        }

        private int _gamma = 1;
        public int gamma
        {
            get { return _gamma; }
            set
            {
                Set(ref _gamma, value);

            }
        }


        private int _constx = 100;
        public int constx
        {
            get { return _constx; }
            set
            {
                Set(ref _constx, value);

            }
        }

        private int _Sharp = 0;
        public int Sharp
        {
            get { return _Sharp; }
            set
            {
                Set(ref _Sharp, value);

            }
        }
        private int _SharpK = 3;
        public int SharpK
        {
            get { return _SharpK; }
            set
            {
                Set(ref _SharpK, value);

            }
        }
        public string _EnhanceType = EnumHelper.GetEnumDescription(EnhanceTypes.BrightAdjust);
        [Newtonsoft.Json.JsonIgnore]
        public string EnhanceType
        {
            get { return _EnhanceType; }
            set
            {
                Set(ref _EnhanceType, value);
                UpdateThresholdVisible();
            }
        }

        private Visibility _RuiHuaQiangduVisible = Visibility.Collapsed;
        public Visibility RuiHuaQiangduVisible
        {
            get { return _RuiHuaQiangduVisible; }
            set { Set(ref _RuiHuaQiangduVisible, value); }
        }

        private Visibility _RuiHuaHeVisible = Visibility.Collapsed;
        public Visibility RuiHuaHeVisible
        {
            get { return _RuiHuaHeVisible; }
            set { Set(ref _RuiHuaHeVisible, value); }
        }
        private Visibility _DuibiduVisible = Visibility.Collapsed;
        public Visibility DuibiduVisible
        {
            get { return _DuibiduVisible; }
            set { Set(ref _DuibiduVisible, value); }
        }
        private Visibility _GammaVisible = Visibility.Collapsed;
        public Visibility GammaVisible
        {
            get { return _GammaVisible; }
            set { Set(ref _GammaVisible, value); }
        }

        private Visibility _LowThresholdVisible = Visibility.Visible;
        public Visibility LowThresholdVisible
        {
            get { return _LowThresholdVisible; }
            set { Set(ref _LowThresholdVisible, value); }
        }

        private Visibility _HightThresholdVisible = Visibility.Visible;
        public Visibility HightThresholdVisible
        {
            get { return _HightThresholdVisible; }
            set { Set(ref _HightThresholdVisible, value); }
        }



        private Dictionary<string, object> _paramEnum = new Dictionary<string, object>();
        [Newtonsoft.Json.JsonIgnore]
        public Dictionary<string, object> ParamEnum
        {
            get { return _paramEnum; }
            set { Set(ref _paramEnum, value); }
        }



        // 整型
        private Dictionary<string, int> _paramInt = new Dictionary<string, int>();
        [Newtonsoft.Json.JsonIgnore]
        public Dictionary<string, int> ParamInt
        {
            get { return _paramInt; }
            set
            {
                Set(ref _paramInt, value);

            }

        }








        //二值化
        public void Enhanceupdata(CImageEnhanceTool cImageEnhance)
        {//阈值方式
            cImageEnhance.SetRunParam("EnhanceType", ParamMap[EnhanceType]);
            //值

            cImageEnhance.SetRunParam("BrightGain", Zengyi.ToString());
            cImageEnhance.SetRunParam("BrightOffset", Light.ToString());
            cImageEnhance.SetRunParam("SharpenKernelSize", SharpK.ToString());
            cImageEnhance.SetRunParam("SharpenFactor", Sharp.ToString());
            cImageEnhance.SetRunParam("ContrastFactor", constx.ToString());
            cImageEnhance.SetRunParam("GammaVal", gamma.ToString());
        }



        private void UpdateThresholdVisible()
        {
            switch (EnhanceType)
            {
                case "亮度校正":
                    LowThresholdVisible = Visibility.Visible;
                    HightThresholdVisible = Visibility.Visible;
                    RuiHuaHeVisible = Visibility.Collapsed;
                    RuiHuaQiangduVisible = Visibility.Collapsed;
                    DuibiduVisible = Visibility.Collapsed;
                    GammaVisible = Visibility.Collapsed;

                    break;
                case "伽马":
                    LowThresholdVisible = Visibility.Collapsed;
                    HightThresholdVisible = Visibility.Collapsed;
                    RuiHuaHeVisible = Visibility.Collapsed;
                    RuiHuaQiangduVisible = Visibility.Collapsed;
                    DuibiduVisible = Visibility.Collapsed;
                    GammaVisible = Visibility.Visible;

                    break;
                case "对比度":
                    LowThresholdVisible = Visibility.Collapsed;
                    HightThresholdVisible = Visibility.Collapsed;
                    RuiHuaHeVisible = Visibility.Collapsed;
                    RuiHuaQiangduVisible = Visibility.Collapsed;
                    DuibiduVisible = Visibility.Visible;
                    GammaVisible = Visibility.Collapsed;

                    break;
                case "锐化":
                    LowThresholdVisible = Visibility.Collapsed;
                    HightThresholdVisible = Visibility.Collapsed;
                    RuiHuaHeVisible = Visibility.Visible;
                    RuiHuaQiangduVisible = Visibility.Visible;
                    DuibiduVisible = Visibility.Collapsed;
                    GammaVisible = Visibility.Collapsed;

                    break;

                default:
                    break;
            }
        }


    }


    /// <summary>
    /// 输出图像
    /// </summary>

    public enum OutImageTypes
    {
        原图,
        图像增强,

    }

    /// <summary>
    /// 阈值方式
    /// </summary>

    public enum EnhanceTypes
    {
        [Description("锐化")]
        Sharpen,

        [Description("对比度")]
        Contrast,

        [Description("伽马")]
        Gamma,

        [Description("亮度校正")]
        BrightAdjust,




    }



}

